<?php
namespace logic\sys\config;
/**
 * 网站配置表
 */
class ConfigManage extends \logic\Base{
    
    
    public function __construct(\logic\user\User $User){
        parent::__construct($User);
        if( !in_array( $User->role , ['admin','site'])) logicE('请勿非法操作');
    }
    
    public function find($param){
        return D("Config",'sys')->find($param);
    }
        
    /**
     * 添加一个配置【平台】
     */
    public function add($data){        
        $check = [
            'type'      => ['check'=>'must','msg'=> '类型不能为空','reg'=> [1,2,3]],
            'tag'       => ['check'=>'must','msg'=> '配置标识不能为空'],
            'name'      => ['check'=>'must','msg'=> '配置名称不能为空'],
            'note'      => '',
            'content'   => '',
        ];        
        $save = pVerify($check,$data);
        if(is_array($save['content'])) $save['content'] = json_encode($save['content']);
        $id = D("Config",'sys')->add($save);
        return $id;
    }
    
    /**
     * 平台修改 修改一个配置
     */
    public function AdminEdit($id,$param){
        $role = $this->CallUser->getRoleInfo();
        if( $role['isroot'] ){
            $check = [
                'type'      => ['msg'=> '类型不能为空','reg'=> [1,2,3]],
                'tag'       => ['check'=>'must','msg'=> '配置标识不能为空'],
                'name'      => ['check'=>'must','msg'=> '配置名称不能为空'],
                'note'      => '',
                'content'   => '',
            ];   
        }else{
            $check = [
                'content'   => '',
            ];
        }             
        $save = pVerify($check,$param);
        $result = D("Config",'sys')->edit($id,$save);
        return $result;
    }
    
    /**
     * 站点修改 修改一个配置
     */
    public function SiteEdit(){
        
    }
    
    /**
     * 列表读取
     */
    public function getAdminList($param){
        return D("Config",'sys')->getList($param);
    }
    
}